package avicit.bdp.dms.perm.rest;

import avicit.bdp.dms.perm.dto.DataSecretDTO;
import avicit.bdp.dms.perm.service.DataSecretService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2021-03-25
 * @类说明：DataSecretRest
 * @修改记录：
 * @注意事项：
 * @主要功能：密级管理
 */
@RestController
@Api(tags = "数据权限管理API接口")
@RequestMapping("/api/bdp/dms/secret")
public class DataSecretRest {
    @Autowired
    private DataSecretService dataSecretService;

    /**
     * 启用密级管理功能时，设置需要拦截的用户列表
     * @param dataSecretDto
     * @return
     */
    @PostMapping("/enableDataSecret")
    @ApiOperation(value = "启用密级管理功能时，设置需要拦截的用户列表")
    public ResponseMsg addDataSecret(@RequestBody DataSecretDTO dataSecretDto) {
        ResponseMsg responseMsg = new ResponseMsg<>();

        this.dataSecretService.addDataSecret(dataSecretDto);

        return responseMsg;
    }

    /**
     * 停用密级管理功能时，删除设置的用户列表
     * @param dataSecretDto
     * @return
     */
    @DeleteMapping("/disableDataSecret")
    @ApiOperation(value = "停用密级管理功能时，删除设置的用户列表")
    public ResponseMsg removeDataSecret(@RequestBody DataSecretDTO dataSecretDto) {
        ResponseMsg responseMsg = new ResponseMsg<>();

        this.dataSecretService.removeDataSecret(dataSecretDto);

        return responseMsg;
    }

    /**
     * 修改密级管理需要拦截的用户列表
     * @param dataSecretDto
     * @return
     */
    @PostMapping("/updateDataSecret")
    @ApiOperation(value = "修改密级管理需要拦截的用户列表")
    public ResponseMsg updateDataSecret(@RequestBody DataSecretDTO dataSecretDto) {
        ResponseMsg responseMsg = new ResponseMsg<>();

        this.dataSecretService.updateDataSecret(dataSecretDto);

        return responseMsg;
    }

    /**
     * 列举当前密级管理需要拦截的用户列表
     * @return
     */
    @GetMapping("/listDataSecrets")
    @ApiOperation(value = "列举权限列表")
    public ResponseMsg<QueryRespBean<DataSecretDTO>> listDataSecrets() {
        ResponseMsg<QueryRespBean<DataSecretDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.dataSecretService.listDataSecrets());

        return responseMsg;
    }
}
